// initUpload, uploadChunk, mergeFile
import { URLSearchParamsUtils } from 'sunrise-utils'
import request, { IPage, IWorkspaceResponse, IListWorkspaceResponse } from '@/api/http/request'
import { IModel } from '../types/model'

const HTTP_PREFIX = '/manage/api/v1'

export const initUpload = async (file: any) => {
  const params = URLSearchParamsUtils(file)
  const response = await request.post(`${HTTP_PREFIX}/model/initUpload?${params}`)
  return response.data
}
export const uploadChunkApi = async (file: FormData) => {
  const response = await request.post(`${HTTP_PREFIX}/model/uploadChunk`, file, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
  return response.data
}
export const mergeFile = async (uploadId: string) => {
  const response = await request.post(`${HTTP_PREFIX}/model/mergeFile?uploadId=${uploadId}`)
  return response.data
}

export const getModelsApi = async (params: any): Promise<{ data: { list: IModel[] }, code: number }> => {
  const newParams = URLSearchParamsUtils(params)
  const response = await request.get(`${HTTP_PREFIX}/model/getModelList?${newParams}`)
  return response.data
}

// 删除模型
export const deleteModelApi = async (id: string) => {
  const response = await request.delete(`${HTTP_PREFIX}/model/deleteModel?uploadId=${id}`)
  return response.data
}

// 编辑模型是否显示已经模型名称修改
export const editModelApi = async (params: any) => {
  const newParams = URLSearchParamsUtils(params)
  const response = await request.post(`${HTTP_PREFIX}/model/editModelInfo?${newParams}`)
  return response.data
}

// 检测当前已上传的进度
export const checkUploadProgressApi = async (uploadId: string) => {
  const response = await request.get(`${HTTP_PREFIX}/model/getUploadInfo?uploadId=${uploadId}`)
  return response.data
}
